package com.example.bitintershipbbs.controller;

import com.example.bitintershipbbs.DTO.PostList;
import com.example.bitintershipbbs.mapper.PostMapper;
import jdk.nashorn.internal.ir.ReturnNode;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@CrossOrigin
@Controller
public class IndexController {
    @Autowired
    private PostMapper postMapper;
    @GetMapping("/")
    public ResponseEntity<Object> getIndex(){
        PostList postList = new PostList();
        postList.setCount(10);
        postList.setContent(postMapper.getLatest10());
        return ResponseEntity.status(200).body(postList);
    }

    @GetMapping("/userpost")
    public ResponseEntity<Object> getUserPost(@Param("id") Integer id){
        PostList postList = new PostList();
        postList.setContent(postMapper.getListById(id));
        postList.setCount(postList.getContent().size());
        return ResponseEntity.status(200).body(postList);
    }
}
